<?php
// +----------------------------------------------------------------------
// | HkCms 地区分站
// +----------------------------------------------------------------------
// | Author: xiaowu
// +----------------------------------------------------------------------

declare (strict_types=1);

namespace app\index\controller;
use app\index\model\cms\Category;
use think\facade\Db;

use app\admin\model\cms\Model;

class Substation extends BaseController
{
	public function initialize()
    {
        parent::initialize();

        // 非开发者模式下,屏蔽非致命错误
        if (!$this->app->isDebug()) {
            // 屏蔽掉notice错误
            //error_reporting(E_ERROR & ~E_WARNING & ~E_NOTICE);
            error_reporting(E_ERROR);
        }
        //xiaowu
		$lang = get_curlang();
		$this->view->assign('lang', $lang);
		if(site('content_lang_on')==1)
		{
			$langurl="/".$lang."/substation/";
		}
		else
		{
			$langurl="/substation/";
		}
		$this->view->assign('langurl', $langurl);
		//xiaowu		
    }
	
	public function index()
    {
		//xiaowu		
		//$dir = root_path().'template'.DIRECTORY_SEPARATOR.'index/'.site('index_theme').'/';	
		$dir = get_template_path('index');
        $viewfile = 'substation/index';
		if (!empty($lang)) {
            $viewfilepath = $dir.$viewfile."_".$lang.".html";
						
            if (file_exists($viewfilepath)) {
                $viewfile .= "_".$lang;
            }
        }
		//xiaowu
		
		return $this->view->fetch($viewfile);
    }
	
	public function list()
    {
        //xiaowu
		$lang = get_curlang();
		$this->view->assign('lang', $lang);
		//xiaowu
		$math = $this->request->param('math','');
		$substation = Db::name('substation')->where(['math'=>$math])->find();
		$this->view->assign('substationmath', $substation['math']);
		$this->view->assign('substationname', $substation['name']);
		
		if (!empty($substation['seotitle'])) {
			$seo_title=$substation['seotitle'];
		}
		else
		{
			$home_title=site('home_title');
			$seo_title_list = explode(',', $home_title);
			$seo_title = '';
			foreach($seo_title_list as $i=>$k) 
			{
			   if ($i > 0) {
				 $seo_title .= ",".$substation['name'].$seo_title_list[$i];
			   }
			   else
			   {
				 $seo_title .= $substation['name'].$seo_title_list[$i]; 
			   }  
			}
		}
		if (!empty($substation['keywords'])) {
			$seo_keywords=$substation['keywords'];
		}
		else
		{
			$home_keyword=site('keyword');
			$seo_keyword_list = explode(',', $home_keyword);
			$seo_keyword = '';
			foreach($seo_keyword_list as $i=>$k) 
			{
			   if ($i > 0) {
				 $seo_keyword .= ",".$substation['name'].$seo_keyword_list[$i];
			   }
			   else
			   {
				 $seo_keyword .= $substation['name'].$seo_keyword_list[$i]; 
			   }  
			}
		}
		if (!empty($substation['description'])) {
			$seo_description=$substation['description'];
		}
		else
		{
			$home_description=site('description');
			$seo_description_list = explode(',', $home_description);
			$seo_description = '';
			foreach($seo_description_list as $i=>$k) 
			{
			   if ($i > 0) {
				 $seo_description .= ",".$substation['name'].$seo_description_list[$i];
			   }
			   else
			   {
				 $seo_description .= $substation['name'].$seo_description_list[$i]; 
			   }  
			}
		}
		$this->view->assign('seo_title', $seo_title);
        $this->view->assign('seo_keywords', $seo_keyword);
        $this->view->assign('seo_desc', $seo_description);
		//xiaowu		
		$dir = get_template_path('index');
        $viewfile = 'substation/list';
		if (!empty($lang)) {
            $viewfilepath = $dir.$viewfile."_".$lang.".html";
						
            if (file_exists($viewfilepath)) {
                $viewfile .= "_".$lang;
            }
        }
		//xiaowu
		
		return $this->view->fetch($viewfile);
    }	
}